package com.lvmama.monkey.config

import com.typesafe.config.{Config, ConfigFactory}
import scala.collection.JavaConversions._

/**
  * Created by hejing on 2017/10/12.
  */
case class JobConfig(
                      spark: Map[String, String],
                      param: Map[String,String]
                    )
object JobConfig {

  type ConfigType = Map[String, String]

  def apply(): JobConfig = {
    apply(ConfigFactory.load)
  }

  def apply(applicationConfig: Config): JobConfig = {

    val config = applicationConfig.getConfig("defaultConfig")

    new JobConfig(
      transform2Map(config, "spark"),
      transform2Map(config, "param")
    )
  }

  private def transform2Map(config: Config, configName: String): ConfigType = {
    config.getObject(configName).unwrapped().toMap.asInstanceOf[ConfigType]
    //要import scala.collection.JavaConversions._，否则无法解析toMap
  }

}